package com.bdzl.admin.controller.sys;

import java.util.List;
import java.util.Map;

import com.bdzl.pub.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import com.bdzl.pub.entity.sys.ApiLogDO;
import com.bdzl.admin.service.sys.ApiLogService;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;

/**
 * 接口日志表
 * 
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-03-23 13:59:22
 */
 
@Controller
@RequestMapping("/bdzl/apiLog")
public class ApiLogController extends BaseController {
	@Autowired
	private ApiLogService apiLogService;
	
	@GetMapping()
	String ApiLog(){
	    return "bdzl/apiLog/apiLog";
	}
	
	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<ApiLogDO> apiLogList = apiLogService.list(query);
		int total = apiLogService.count(query);
		PageUtils pageUtils = new PageUtils(apiLogList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	String add(){
	    return "bdzl/apiLog/add";
	}

	@PostMapping("/edit")
	@ResponseBody
	ApiLogDO edit(@RequestBody ApiLogDO apiLog){
		apiLog = apiLogService.get(apiLog.getApiId());
	    return apiLog;
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save( ApiLogDO apiLog){
		if(apiLogService.save(apiLog)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( ApiLogDO apiLog){
		apiLogService.update(apiLog);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove(@RequestBody ApiLogDO apiLog){
		if(apiLogService.remove(apiLog.getApiId())>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] apiIds){
		apiLogService.batchRemove(apiIds);
		return R.ok();
	}
	
}
